﻿@model Bricks.Site.Models.BidInfo.BidListView

@{
    ViewBag.Title = "招标管理";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

@*实现对EasyUI的DataGird控件操作的JS代码*@
<script type="text/javascript">
    $(function () {
        initTable();
    });
    function initTable(queryData) {
        $('#bidGrid').datagrid({
            url: '/BidInfo/GetDataList',
            nowrap: true,
            autoRowHeight: false,
            striped: true,
            collapsible: true,
            rownumbers: true,
            remoteSort: false,
            idField: 'ID',
            checkOnSelect: true,
            selectOnCheck: true,
            singleSelect: true,
            queryParams: queryData,
            columns: [[
                { title: '@Html.LabelFor(m => m.ProjectName)', field: 'ProjectName', width: 220, sortable: true },
                { title: '@Html.LabelFor(m => m.BidDate)', field: 'BidDate', width: 90, sortable: true },
                { title: '@Html.LabelFor(m => m.BidCount)', field: 'BidCount', width: 60, sortable: true },
                { title: '@Html.LabelFor(m => m.BidTitle)', field: 'BidTitle', width: 350, sortable: true },
                { title: '@Html.LabelFor(m => m.BidType)', field: 'BidType', width: 80, sortable: true }
            ]],
            toolbar: '#bidToolBar',
            //合并单元格
            onLoadSuccess: function (data) {
                if (data.rows.length > 1) {
                    mergeCellsByField("bidGrid", "ProjectName");
                }
            },
            //双击弹出预览
            onDblClickRow: function (rowIndex, rowData) {
                BidInfo.Preview();
            }
        });
    }

    var BidInfo = {
        //新增
        Add: function () {
            BidInfo.Mutual("新增", "/BidInfo/Edit", true);
        },

        //修改
        Edit: function () {
            var row = $("#bidGrid").datagrid("getSelections");
            if (row.length == 1) {
                BidInfo.Mutual("修改", "/BidInfo/Edit?ID=" + row[0].ID, false);
            }
            else { $.EasyuiSlide("请选择一条记录"); }
        },

        //实体操作
        Mutual: function (title, href, isAdd) {
            $.ModelDialog({
                dialogid: "editDialog",
                title: title, href: href, width: 800,
                handler: function () {

                    BidInfo.EndSectionEdit();  //结束编辑

                    $.ModelForm({
                        validate: true, button: $(this),
                        id: "#bid-model",
                        url: "/BidInfo/EditPost",
                        success: function (result) {

                            //保存标段列表
                            var data = $('#sectionGrid').datagrid('getRows');  //取得所有数据
                            //Modify By Luozx 2014-02-14：此处需要补充属性
                            if (data != null && data.length > 0) {
                                var dataJson = JSON.stringify(data);
                                var effectRow = new Object();
                                effectRow["Data"] = dataJson;
                                $.post("/BidInfo/SaveSectionList?bidID=" + result.AppendData.ID, effectRow, function (listResult) {  //result.AppendData为返回的对象
                                    try {
                                        listResult = JSON.parse(listResult);
                                        if (listResult.ResultType == 0) {  //ResultType是在OperationResultType定义的，0表示Success成功
                                            $.EasyuiSlide(listResult.Message);  //弹出右下角提示
                                            //options.success(result);

                                            //关闭窗体
                                            //var button = $("#btnClose");
                                            //$.ButtonCloseDialog(button);
                                        }
                                        else {
                                            //如果失败，还是使每一行处于编辑状态
                                            //var list = $('#actionDataGrid').datagrid('getData').rows;
                                            //for (var i = 0; i < list.length; i++) {
                                            //    //Assign.EditRow(i);
                                            //    $('#actionDataGrid').datagrid('beginEdit', i);
                                            //}
                                            $.EasyuiMsg(listResult.Message);  //弹出提示窗体
                                        }
                                    } catch (e) { $.Error(listResult); }
                                });

                                //$.EasyuiSlide("招标确认" + data.length);
                            }
                            BidInfo.Reload();
                        }
                    });
                    //debugger;
                    ////保存form内容
                    //$("#bid-model").form("submit", {
                    //    url: "/BidInfo/EditPost", onSubmit: submit,
                    //    success: function (result) {
                    //        $.HideMask();
                    //        try {
                    //            result = JSON.parse(result);
                    //            if (result.ResultType == 0) {  //ResultType是在OperationResultType定义的，0表示Success成功
                    //                $.EasyuiSlide(result.Message);  //弹出右下角提示
                    //                options.success(result);
                    //                $.ButtonCloseDialog(options.button);
                    //            }
                    //            else {
                    //                $.EasyuiMsg(result.Message);  //弹出提示窗体
                    //            }
                    //        } catch (e) { $.Error(result); }
                    //    }
                    //});


                    //$("#editDialog").dialog("destroy");  //关闭当前窗体
                },
                onLoad: function () { BidInfo.FormInit(isAdd); }
            });
        },

        //弹窗初始化
        FormInit: function (isAdd, isPurview) {
            $("#projectID").combobox({
                width: 674, panelHeight: "auto",
                url: "/ProjectInfo/GetDataList",
                valueField: 'ID',
                textField: 'ProjectName',
                editable: false,
                //如果是新增，则让下拉框默认选中第一个
                onLoadSuccess: function () {
                    if (isAdd) {
                        var data = $('#projectID').combobox('getData');
                        if (data.length > 0) {
                            $('#projectID').combobox('select', data[0]["ID"]);
                        }
                    }
                }
            });

            //$.DictionaryComboList("#bidType", "BidType", isAdd);  //建设类别

            $("#bidType").combobox({
                width: 150, panelHeight: "auto",
                url: "/Dictionary/GetDictionaryByTypeTag?typeTag=BidType",
                valueField: "DictionaryName",
                textField: "DictionaryName",
                editable: false,
                //如果是新增，则让下拉框默认选中第一个
                onLoadSuccess: function () {
                    if (isAdd) {
                        var data = $("#bidType").combobox('getData');
                        if (data.length > 0) {
                            $("#bidType").combobox('select', data[0]["DictionaryName"]);
                        }
                    }
                    if (!isPurview) {
                        //如果是自行招标，则清空招标代理的值，且只读
                        if ($("#bidType").combobox('getValue') == "自行招标") {
                            $("#bidAgent").val("");
                            document.getElementById("bidAgent").readOnly = true;
                        }
                        else {
                            document.getElementById("bidAgent").readOnly = false;
                        }
                    }
                },
                onSelect: function () {
                    if (!isPurview) {
                        //如果是自行招标，则清空招标代理的值，且只读
                        if ($("#bidType").combobox('getValue') == "自行招标") {
                            $("#bidAgent").val("");
                            document.getElementById("bidAgent").readOnly = true;
                        }
                        else {
                            document.getElementById("bidAgent").readOnly = false;
                        }
                    }
                }
            });
        },

        //预览
        Preview: function () {
            var row = $("#bidGrid").datagrid("getSelections");
            if (row.length == 1) {
                BidInfo.PreviewMutual("预览", "/BidInfo/Preview?ID=" + row[0].ID, false);
            }
            else { $.EasyuiSlide("请选择一条记录"); }
        },

        //实体操作
        PreviewMutual: function (title, href, isAdd) {
            $.ModelDialog({
                title: title, href: href, width: 800,
                onLoad: function () { BidInfo.FormInit(isAdd, true); }
            });
        },

        //结束编辑
        EndSectionEdit: function () {
            var rows = $('#sectionGrid').datagrid('getRows');
            for (var i = 0; i < rows.length; i++) {
                $('#sectionGrid').datagrid('endEdit', i);
            }
        },

        //删除
        Delete: function () {
            var row = $("#bidGrid").datagrid("getSelected");
            if (row) {
                $.messager.confirm('操作提示', "确认删除选中项吗？", function (r) {
                    if (r) {
                        $.post("/BidInfo/Delete?ID=" + row.ID, function (result) {
                            if (result.ResultType == 0) {  //0表示成功
                                //移除删除的数据
                                $.EasyuiSlide(result.Message);
                                BidInfo.Reload();
                            }
                            else {
                                $.EasyuiMsg(result.Message);
                            }
                        });
                    }
                });
            }
            else {
                $.EasyuiSlide("请选择一条记录");
            }
        },

        //重新加载数据
        Reload: function () {
            $("#bidGrid").datagrid("reload");
        }
    }
</script>

<!--面板（从数据库取得菜单名称和图标等）-->
<div class="easyui-panel" title="招标列表" fit="true">
    <table id="bidGrid" fit="true"></table>
    @*<div id="bidToolBar">
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='BidInfo.Add()' data-options='plain:true,iconCls:"icon-application_add"'>新增</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='BidInfo.Edit()' data-options='plain:true,iconCls:"icon-application_delete"'>修改</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='BidInfo.Delete()' data-options='plain:true,iconCls:"icon-bell"'>删除</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='BidInfo.Disable()' data-options='plain:true,iconCls:"icon-bank"'>禁用</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='BidInfo.Enable()' data-options='plain:true,iconCls:"icon-bestseller"'>启用</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='BidInfo.Up()' data-options='plain:true,iconCls:"icon-up"'>向上</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='BidInfo.Down()' data-options='plain:true,iconCls:"icon-down"'>向下</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='BidInfo.Reload()' data-options='plain:true,iconCls:"icon-blue_lego"'>刷新</a>
    </div>*@
    <div id="bidToolBar">@Html.Raw(ViewBag.ToolBarInfo)</div>
</div>
